package com.kevin.kitchenshow2.adapter;

import java.util.List;

import com.kevin.kitchenshow2.R;
import com.kevin.kitchenshow2.entity.Category;
import com.kevin.kitchenshow2.entity.SubCategory;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class SubcateAdapter extends BaseAdapter {
	private List<SubCategory> lstSubcate;
	private Context context;
	private LayoutInflater inflater;

	public SubcateAdapter() {
		// TODO Auto-generated constructor stub
	}

	public SubcateAdapter(Context context, List<SubCategory> lstSubcate) {
		this.context = context;
		this.lstSubcate = lstSubcate;
		inflater = LayoutInflater.from(this.context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return lstSubcate == null ? 0 : lstSubcate.size();
	}

	@Override
	public SubCategory getItem(int pos) {
		// TODO Auto-generated method stub
		return pos < 0 || lstSubcate == null || pos >= lstSubcate.size() ? null
				: lstSubcate.get(pos);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		SubcateHoler holder;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.subcate_list_item, null);
			holder = new SubcateHoler();
			holder.imvSubcate = (ImageView) convertView
					.findViewById(R.id.imvSubcate);
			holder.txvName = (TextView) convertView
					.findViewById(R.id.txvSubcate);
			// holder.status.
			convertView.setTag(holder);
		} else {
			holder = (SubcateHoler) convertView.getTag();
		}

		if (lstSubcate != null && position >= 0 && position < lstSubcate.size()) {
			holder.imvSubcate.setImageDrawable(lstSubcate.get(position)
					.getImage());
			holder.txvName.setText(lstSubcate.get(position).getName());
		}

		// holder.txvInfo.setText(lstItems.get(position).getCountryid());
		return convertView;

	}

}
